package cn.rocky.offer;

public class offer21 {

    public int[] exchange(int[] nums) {
        int left = 0,right = nums.length - 1,tmp;
        while (left < right) {
            while(left < right && (nums[left] & 1) == 1) {
                left++;
            }
            while(left < right && (nums[right] & 1) == 0) {
                right--;
            }
            tmp = nums[left];
            nums[left] = nums[right];
            nums[right] = tmp;
        }
        return nums;
    }

    public static void main(String[] args) {
        int[] ans = new int[]{1,2,3,4};
        offer21 offer21 = new offer21();
        int[] exchange = offer21.exchange(ans);
        for (int i:exchange) {
            System.out.println(i);
        }
    }
}
